home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 130_01 / gc0.c < prev    next >
Text File  |  1985-03-09  |  10KB  |  399 lines

  1. /********************************************************
  2.  *                                                      *
  3.  *              BDS-C Supplementary Library             *
  4.  *                      release 2                       *
  5.  *                                                      *
  6.  *              Steve de Plater, Nov. 1980              *
  7.  *                    66 Priam St.                      *
  8.  *                    Chester Hill,                     *
  9.  *                    NSW, 2162                         *
  10.  *                    Australia                         *
  11.  *              Phone: (02) 644 4009                    *
  12.  *                                                      *
  13.  *              This file: GC0.C   release 1            *
  14.  *                                                      *
  15.  ********************************************************/
  16.  
  17. /*=======================================================
  18.  
  19.         This routine creates a standard inverse video
  20.         character set for the Exidy Sorcerer.
  21.         The inverse character generator resides in both
  22.         the standard and user graphics areas (ie from
  23.         0xfc00 through to 0xffff).
  24. */
  25.  
  26. invid()
  27. {
  28.         int *p1,*p2;
  29.  
  30.         for (p1=0xf800,p2=0xfc00;p2;*p2++=~(*p1++));
  31. }
  32.  
  33. /*=======================================================*/
  34.  
  35. pgraf(filename)
  36. char *filename;
  37.  
  38. /*      This is "pgraf" which:
  39.           (1)   creates a file called "filename",
  40.           (2)   writes the graphics areas of the Sorcerer
  41.                 (ie char generators for ASCII characters
  42.                  0x80 to 0xFF) to the file just created.
  43.         The return codes are:
  44.           (1)   0 if successful, or
  45.           (2)   -1 otherwise.
  46.         This allows statements of the form:
  47.         "if pgraf("mygrafix.txt") goodsave();"
  48. */
  49. {
  50.         int fd;
  51.         char *buf;
  52.  
  53.         return swapout(filename,0xfc00,0xffff);
  54. }
  55.  
  56. /*======================================================*/
  57.  
  58. ggraf(filename)
  59. char *filename;
  60.  
  61. /*      This is "ggraf" which:
  62.           (1)   reads the file "filename" into the graphics
  63.                 area of the Sorcerer.
  64.                 No check is made on file length (users beware!)
  65.           (2)   is designed to undo what "pgraf" does.
  66.         The return codes are:
  67.           (1)   0 if successful, or
  68.           (2)   -1 otherwise.
  69.         This allows statements of the form:
  70.         "if ggraf("mygrafix.txt") goodload();"
  71. */
  72. {
  73.         return swapin(filename,0xfc00);
  74. }
  75.  
  76. /*=======================================================
  77.  
  78.         The Standard Exidy Monitor caller!
  79.         Calling sequence is of the form:
  80.           x=monitor("SA IDIOT 100 2BFF 2");
  81.         ie it is passed a pointer to a Standard Monitor
  82.         command string. The required CR is appended
  83.         automatically by this routine.
  84.         The value returned is:
  85.                 0 for an error in the command string,
  86.                 1 for a successful operation, or
  87.                 NO RETURN AT ALL for errors caught by
  88.                  the monitor itself (sorry about that!)
  89. */
  90.  
  91. monitor(s)
  92. char *s;
  93.  
  94. {       char    *inbuf;
  95.  
  96.         inbuf = mwa();
  97.         strcpy(inbuf,s);
  98.         while (*inbuf=toupper(*inbuf)) inbuf++;
  99.         *inbuf = '\r';
  100.         return exycall();
  101. }
  102.  
  103. /*=======================================================
  104.  
  105.         This routine returns a character from the
  106.         console device WITHOUT echoing it to the screen
  107. */
  108.  
  109. char inchar()
  110.  
  111. {       return bios(3,0);       }
  112.  
  113. /*=======================================================
  114.  
  115.         This routine returns a STRING from the console
  116.         device WITHOUT echoing it to the screen.
  117.         The string is terminated with a CR (not included
  118.         in the string).
  119.         The return value is the length of the string.
  120.         's' is a pointer to the string space (which must be
  121.         large enough to hold it!)
  122. */
  123.  
  124. char instr(s)
  125. char *s;
  126.  
  127. {       char c, *temp;
  128.  
  129.         temp=s;
  130.         while ((c=bios(3,0)) != '\r')
  131.            *s++=c;
  132.         *s='\0';
  133.         return strlen(temp);
  134. }
  135.  
  136. /*=======================================================
  137.  
  138.         Reads Standard Exidy tape file of name 'name'
  139.         from tape 'unit' into address 'addr'.
  140.         Returns 0 for bad, 1 for ok.
  141. */
  142.  
  143. rtape(name,unit,addr)
  144. char *name;
  145. int   unit, addr;
  146.  
  147. {       char monbuf[50];
  148.  
  149.         sprintf(monbuf,"LO %s %x %x",name,unit,addr);
  150.         return monitor(monbuf);
  151. }
  152.  
  153. /*=======================================================
  154.  
  155.         Writes standard Exidy tape file of 'name' from
  156.         address 'addr1' to address 'addr2' to tape 'unit'.
  157.         Returns 0 for bad, 1 for ok.
  158. */
  159.  
  160. wtape(name,addr1,addr2,unit)
  161. char *name;
  162. int   addr1, addr2, unit;
  163.  
  164. {       char monbuf[50];
  165.  
  166.         sprintf(monbuf,"SA %s %x %x %x",name,addr1,addr2,unit);
  167.         return monitor(monbuf);
  168. }
  169.  
  170. /*=======================================================
  171.  
  172.         Reads standard Exidy tape as in 'rtape' but then
  173.         chains to the execution address on the tape header.
  174.         NO return values (of course!)
  175. */
  176.  
  177. rtapeg(name,unit,addr)
  178. char *name;
  179. int   unit, addr;
  180.  
  181. {       char monbuf[50];
  182.  
  183.         sprintf(monbuf,"LOG %s %x %x",name,unit,addr);
  184.         monitor(monbuf);
  185. }
  186.  
  187. /*=======================================================
  188.  
  189.         Undoes what swapin does:
  190.         ie swaps out to a filename pointed to by name
  191.         the contents of memory between saddr and eaddr
  192.         (inclusive).
  193.         Actually the end addr is calculated to the next
  194.         128 bytes ABOVE if the amount of data to be transferred
  195.         is not actually a multiple of 128.
  196.         Previous contents are discarded.
  197.         Returns either
  198.                 0 if successful, or
  199.                 -1 otherwise.
  200. */
  201.  
  202. swapout(name,saddr,eaddr)
  203. char *name;
  204. int   saddr, eaddr;
  205.  
  206. {       int     nbl;
  207.         int     fd;
  208.  
  209.         if ((fd=creat(name)) == -1) return fd;
  210.         nbl=((eaddr-saddr)/128)+1;
  211.         if (write(fd,saddr,nbl) != nbl) {
  212.            unlink(name);
  213.            return -1;
  214.         }
  215.         close(fd);
  216.         return 0;
  217. }
  218.  
  219. /*=======================================================
  220.  
  221.         Fills the plot area from the string pointed to
  222.         by s. The string is reused until the plot area
  223.         is full.
  224.         The address of the (0,0) position of the screen
  225.         is returned.
  226. */
  227.  
  228. fillplot(s)
  229. char *s;
  230.  
  231. {
  232.         int *pbase,*psize;
  233.  
  234.         pbase=getplot();
  235.         psize=pbase+3;        /* pointers are NOT integers! */ 
  236.         fill(*pbase,*psize,s,1);
  237.         return *pbase;        /* return the screen RAM addr */
  238. }
  239.  
  240. /*=======================================================
  241.  
  242.         If (mode==0)
  243.           fills the plot area from the beginning of the
  244.           current line to the cursor address.
  245.         else
  246.           fills the plot area from the cursor address to
  247.           the end of the current line.
  248.  
  249.         The string pointed to by s is used as many times
  250.         as needed to fill the area.
  251.  
  252.         Returns the cursor address.
  253. */
  254.  
  255. linefill(mode,s)
  256. char *s;
  257. int mode;
  258.  
  259. {       int csr,k,l,*pbase,*ysize,*xsize;
  260.  
  261.         csr=cursor(-1);
  262.         pbase=getplot();
  263.         ysize=pbase+1;
  264.         xsize=ysize+1;
  265.         l=*pbase;
  266.         for (k=0;k<*xsize;k++)
  267.         {
  268.           if (l>csr) break;
  269.           l+=*ysize;
  270.         }
  271.  
  272.  
  273.         if (mode==0)
  274.         {
  275.           k=l-*ysize;
  276.           fill(k,csr,s,0);
  277.         }
  278.         else
  279.         {
  280.           k=l-1;
  281.           fill(csr,k,s,0);
  282.         }
  283.         return csr;     /* return the cursor position */
  284. }
  285.  
  286. /*=======================================================
  287.  
  288.         if (mode==0)
  289.           fills from the beginning of the screen to
  290.           the cursor.
  291.         else
  292.           fills from the cursor to the end of the screen.
  293.  
  294.         The string pointed to by s is used as many times
  295.         as required to fill.
  296.  
  297.         Returns the cursor address.
  298.